<?php

register_nav_menus(array(
    'primany_menu' => 'Primary Menu'
));

if (function_exists('register_sidebar')) {
    if (function_exists('register_sidebar')) {
        register_sidebar(array(
            'name' => 'Top Left Advertise',
            'before_widget' => '',
            'after_widget' => ''
        ));
        register_sidebar(array(
            'name' => 'Top Right Advertise',
            'before_widget' => '',
            'after_widget' => ''
        ));
        register_sidebar(array(
            'name' => 'Left Sidebar',
            'before_widget' => '<div class="left_widget">',
            'after_widget' => '</div>',
            'before_title' => '<h3>',
            'after_title' => '</h3>'
        ));
        register_sidebar(array(
            'name' => 'Right Sidebar',
            'before_widget' => '<div class="right_widget">',
            'after_widget' => '</div>',
            'before_title' => '<h3>',
            'after_title' => '</h3>'
        ));
    }
}

function excerpt($limit) {
    $excerpt = explode(' ', get_the_excerpt(), $limit);
    if (count($excerpt) >= $limit) {
        array_pop($excerpt);
        $excerpt = implode(" ", $excerpt) . '...';
    } else {
        $excerpt = implode(" ", $excerpt);
    }
    $excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt);
    return $excerpt;
}

function content($limit) {
    $content = explode(' ', get_the_content(), $limit);
    if (count($content) >= $limit) {
        array_pop($content);
        $content = implode(" ", $content) . '...';
    } else {
        $content = implode(" ", $content);
    }
    $content = preg_replace('/\[.+\]/', '', $content);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    return $content;
}


/*** Theme Options ***/
function setup_theme_admin_menus() {
    add_submenu_page('themes.php', 
        'Theme Options', 'Theme Option', 'manage_options', 
        'theme_option', 'theme_option'); 
}

add_action("admin_menu", "setup_theme_admin_menus");

function theme_option() {
    include 'theme_options.php';
}

function register_mysettings() { // whitelist options
    register_setting('option-group', 'theme_logo');
    register_setting('option-group', 'theme_slogan');
    register_setting('option-group', 'slogan_color');
}

add_action( 'admin_init', 'register_mysettings' );